package com.hlt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hlt.dto.UserStatsPageQueryDTO;
import com.hlt.entity.UserStats;
import com.hlt.mapper.UserStatsMapper;
import com.hlt.result.PageResult;
import com.hlt.service.IUserStatsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lzf
 * @since 2024-11-25
 */
@Service
public class UserStatsServiceImpl extends ServiceImpl<UserStatsMapper, UserStats> implements IUserStatsService {

    /**
     * 分页查询
     * 
     * @param userStatsPageQueryDTO
     * @return
     */
    @Override
    public PageResult pageQuery(UserStatsPageQueryDTO userStatsPageQueryDTO) {
        Page<UserStats> page = new Page<>(userStatsPageQueryDTO.getPageNum(), userStatsPageQueryDTO.getPageSize());
        LambdaQueryWrapper<UserStats> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(userStatsPageQueryDTO.getUserId() != null, UserStats::getUserId,
                userStatsPageQueryDTO.getUserId());
        page = page(page, queryWrapper);
        return new PageResult(page.getTotal(), page.getRecords());
    }
}
